﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class GerenciadorItens
    {
        public static List<Item> lista = new List<Item>();

        static Random random = new Random();

        public static double tempoParaAparecer = random.Next(2000, 5000);

        public static int itemQueVaiAparecer = random.Next(0, 3);

        static ContentManager Content;

        SpriteFont fonte;


        public GerenciadorItens(ContentManager Content)
        {
            GerenciadorItens.Content = Content;

            fonte = Content.Load<SpriteFont>("arial");
        }

        public void Update(GameTime gameTime)
        {
            if (gameTime.TotalGameTime.TotalMilliseconds > tempoParaAparecer)
            {
                switch (itemQueVaiAparecer)
                {
                    case 0:
                        lista.Add(new Item(Content.Load<Texture2D>("chave"), 0));
                        break;

                    case 1:
                        lista.Add(new Item(Content.Load<Texture2D>("rupie"), 1));
                        break;

                    case 2:
                        lista.Add(new Item(Content.Load<Texture2D>("itemvida"), 2));
                        break;
                }

                tempoParaAparecer = gameTime.TotalGameTime.TotalMilliseconds;
                tempoParaAparecer += random.Next(2000, 5000);

                itemQueVaiAparecer = random.Next(3);

            }

            foreach (Item item in lista)
            {
                item.Update(gameTime);
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            foreach (Item item in lista)
            {
                item.Draw(gameTime, spriteBatch);
            }

            spriteBatch.DrawString(fonte, "tempo: " + tempoParaAparecer + "gametime: " + gameTime.TotalGameTime.TotalMilliseconds.ToString(), new Vector2(200, 300), Color.White);
        }

    }
}
